package com.ruoyi.common.utils.ding;

import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.request.OapiServiceGetCorpTokenRequest;
import com.dingtalk.api.response.OapiServiceGetCorpTokenResponse;
import com.taobao.api.ApiException;

public class DingTokenUtils {

    public static String loadToken(String authCorpId) {
        DefaultDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/service/get_corp_token");
        OapiServiceGetCorpTokenRequest req = new OapiServiceGetCorpTokenRequest();
        req.setAuthCorpid("dingc365fcxxxx");
        OapiServiceGetCorpTokenResponse execute = null;
        try {
            execute = client.execute(req, "accessKey", "accessSecret", "suiteTicket");
        } catch (ApiException e) {
            throw new RuntimeException(e);
        }
        return execute.getAccessToken();
    }
}
